<cfcomponent extends="assets.calgrants.com.Base">

	<cfscript>
        import assets.calgrants.com.bo.County;
	</cfscript>
	
	<cffunction name="get" access="public" output="false" returntype="assets.calgrants.com.bo.County">
		<cfargument name="County_ID" type="numeric" required="true" />
		<cfscript>
			if (arguments.County_ID gt 0) {
				local.loadArgs = {};
				local.loadArgs.obj = new County();
				StructAppend(local.loadArgs, QueryToStruct(read(argumentCollection = arguments))[1]);
				return load(argumentCollection = local.loadArgs);
			} else {
				return new County();
			}
		</cfscript>
	</cffunction>
	
	<cffunction name="load" access="public" output="false" returntype="assets.calgrants.com.bo.County">
		<cfargument name="obj" type="assets.calgrants.com.bo.County" required="true" />
		<cfscript>
			local.obj = arguments.obj;
			if (IsDefined("arguments.County_ID")) {
				local.obj.setCounty_ID(arguments.County_ID);
			}
			if (IsDefined("arguments.Deleted")) {
				local.obj.setDeleted(arguments.Deleted);
			}
			if (IsDefined("arguments.County")) {
				local.obj.setCounty(arguments.County); 
			}
			if (IsDefined("arguments.Region_ID")) {
				local.obj.setRegion_ID(arguments.Region_ID);
			}
			if (IsDefined("arguments.Region")) {
				local.obj.setRegion(arguments.Region);
			}
			if (IsDefined("arguments.Study_Region")) {
				local.obj.setStudy_Region(arguments.Study_Region);
			}
			if (IsDefined("arguments.Date_Created")) {
				local.obj.setDate_Created(arguments.Date_Created);
			}		
			return local.obj;
		</cfscript>
	</cffunction>

	<cffunction name="read" access="public" output="false" returntype="any">
		<cfargument name="County_ID" required="false" default="" />
		<cfargument name="Deleted" required="false" default="0" />
		<cfargument name="County" required="false" default="" />
		<cfargument name="Region_ID" required="false" default="" />
		<cfargument name="Region" required="false" default="" />
		<cfargument name="Study_Region" required="false" default="" />
		<cfargument name="Date_Created" required="false" default="" />

		<cfset var recs = "">
		<cfstoredproc datasource="#getDatasource()#" procedure="readCounty">
			<cfprocparam value="#arguments.County_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.County_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Deleted#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Deleted)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.County#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.County)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Region_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Region_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Region#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Region)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Study_Region#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Study_Region)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Date_Created#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(arguments.Date_Created)) eq 0, true, false)#" />
			<cfprocresult name="recs" />
		</cfstoredproc>
		<cfreturn recs />
	</cffunction>

	<cffunction name="save" access="public" output="false" returntype="any">
		<cfargument name="city" required="true" type="assets.calgrants.com.bo.County" />

		<cfstoredproc datasource="#getDatasource()#" procedure="saveCounty">
			<cfprocparam value="#county.getCounty_ID()#" cfsqltype="CF_SQL_INTEGER" variable="id" type="inout" null="false" />
			<cfprocparam value="#county.getDeleted()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#county.getCounty()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#county.getRegion_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#county.getRegion()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#county.getStudy_Region()#" cfsqltype="CF_SQL_BIT" null="false" />
		</cfstoredproc>
		<cfreturn id />
	</cffunction>

	<cffunction name="destroy" access="public" output="false" returntype="any">
		<cfargument name="County_ID" required="true" />

		<cfstoredproc datasource="#getDatasource()#" procedure="destroyCounty">
			<cfprocparam value="#arguments.County_ID#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="true" cfsqltype="CF_SQL_BIT" null="false" />
		</cfstoredproc>
		<cfreturn true />
	</cffunction>

</cfcomponent>

